﻿namespace IBTrader.Indicator.Oscillator
{
    using IBTrader.Modules.Read;
    using IBTrader.Charts;

    /// <summary>
    /// Williams %R is a momentum indicator that is the inverse of the Fast Stochastic Oscillator. 
    /// As a result, the Fast Stochastic Oscillator and Williams %R produce the exact same lines, only the scaling is different. 
    /// </summary>
    class William : BasePrices
    {
        internal William(Worker worker, int interval = 20) : base(worker, new ChartArgs { Group = 1 }, interval) { }
        public override void Add(object _, Line line)
        {
            Prices.Add(line.Price);
            OnHit(line, NaN(Percent(Prices)));
        }
        internal double Percent(Prices prices)
        {
            var max = prices.Max();
            return (max - prices.Last()) / (max - prices.Min());
        }
    }
}